package com.matt.domain;

import com.dotflat.util.excelUtil.Excel;
import com.matt.commons.exception.BusinessException;
import com.matt.commons.model.Domain;
import com.matt.foundation.constant.ChildrenConstant;
import com.matt.foundation.model.ErrorCode;
import com.matt.foundation.utils.ModelUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.math.BigDecimal;
import java.util.Date;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/7/13
 * *******************************
 */
@Entity
@Data
@Table(name = "children")
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
public class Children extends Domain {

    @Column(columnDefinition = " varchar(32)  COMMENT 'id'")
    @Excel(name = "id")
    private String id;

    @Column(columnDefinition = " varchar(50)  COMMENT '宝宝姓名'")
    @Excel(name = "名称")
    private String name;

//    @Column(columnDefinition = " varchar(5)  COMMENT '删除标记'")
//    private String delFlag;
//    @Column(columnDefinition = " varchar(5)  COMMENT '删除标记'")
//    private String del_flag;

    @ApiModelProperty("学号")
    @Column(columnDefinition = " varchar(100)  COMMENT '学号'")
    private String studentId;
    //推送状态
    @Column(columnDefinition = " int default 0  COMMENT '推送状态 ：0：未推送，1：已推送'")
    private Integer pushStatus;

    @Column(columnDefinition = " varchar(32)  COMMENT ' 学籍号:  行政区划代码+园区顺序号+年份+月份+入园顺序号+性别'")
    private String code;

    @Column(columnDefinition = " varchar(50)  COMMENT '英文名'")
    private String enName;

    @Column(columnDefinition = " varchar(50)  COMMENT '国籍'")
    private String nationality;

    @Column(columnDefinition = " varchar(50)  COMMENT '国籍'")
    private String language;

    @Column(columnDefinition = " varchar(5)  COMMENT '血型'")
    private String bloodType;

    @Column(columnDefinition = " int(3) default 0 COMMENT '户籍类型   0.身份证   2.港澳台胞证  3.出生证明  4.护照'")
    private int idCardType;

    @Column(columnDefinition = " varchar(64)  COMMENT '身份证号'")
    private String idCard;

    @Column(columnDefinition = " varchar(50)  COMMENT '宝宝昵称'")
    private String nickName="";

    @Column(columnDefinition = " int default 0  COMMENT '宝宝性别 ：0：女，1：男'")
    @Excel(name = "性别",readConverterExp = "0=女,1=男,2=未知")
    private Integer gender;

    @Column(name = "aid", columnDefinition = " varchar(32)  COMMENT ' 园区id：园区姓名'")
    @Excel(name = "园区")
    protected String areaId;

    @Column(columnDefinition = " varchar(255)  COMMENT '地址'")
    @Excel(name = "地址")
    private String address = "";

    @Column(columnDefinition = " datetime COMMENT '宝宝生日'")
    @Excel(name = "生日")
    private Date birthday;

    @Column(columnDefinition = " varchar(50)  COMMENT '体重'")
    @Excel(name = "体重")
    private String weight;

    @Column(columnDefinition = " varchar(50)  COMMENT '身高'")
    @Excel(name = "身高")
    private String height;

    @Column(columnDefinition = " varchar(50)  COMMENT '头围'")
    @Excel(name = "头围")
    private String header;

    @Column(columnDefinition = " varchar(255)  COMMENT '备注'")
    private String remark = "";

    @Column(columnDefinition = " varchar(512)  COMMENT '头像地址'")
    private String imgUrl;

//    @Column(columnDefinition = " bigint default 0 COMMENT '焦虑期'")
//    private Long anxietyTime = 0L;
//
//    @Column(name = "createTime", columnDefinition = "datetime default NOW() COMMENT '宝宝生日'")
//    private Date created = new Date();

    @Column(columnDefinition = "datetime COMMENT '课程开始时间'")
    private Date courseStartDate;

    @Column(columnDefinition = "int default 0 COMMENT '托班是否可用， 0:未生效, 1:正常，2 合同结束, 3:已退学，4:已毕学，5，未续费 '")
    private Integer status = 0;

    @Column(columnDefinition = " varchar(32)  COMMENT '录入员工id'")
    private String staffId;

    @Column(columnDefinition = " varchar(50)  COMMENT '对应crm客户id'")
    private String crmClienteleId;

//    @Column(columnDefinition = "bit default false COMMENT '是否展示'")

//    private Boolean isDisplayForAdmin = false;

    @Column(columnDefinition = "longtext COMMENT '托班转班原因'")
    private String nurseryTransferReason;

    @Column(columnDefinition = "longtext COMMENT '早教转班原因'")
    private String earlyTransferReason;
    
    @Column(columnDefinition = "bigdecimal COMMENT '退学金额'")
    private BigDecimal backMoney;

    @Column(columnDefinition = " datetime COMMENT '最近一次测评日期'")
    private Date lastEvaluateDate;

    @Column(columnDefinition = " datetime COMMENT '下次测评日期'")
    private Date nextEvaluateDate;

    @Column(columnDefinition = " varchar(500)  COMMENT '过敏史'")
    private String allergy = "";

    @Column(columnDefinition = " varchar(500)  COMMENT '疾病史'")
    private String diseasesHistory = "";

    @Column(columnDefinition = " varchar(500)  COMMENT '详情状态备注'")
    private String statusRemark = "";

    @Column(columnDefinition = " varchar(50)  COMMENT '户口所在地'")
    private String place = "";

    /** 优惠卷码*/
    @Column(columnDefinition = " varchar(255)  COMMENT '优惠卷码'")
    private String couponCard;

    @Column(columnDefinition = " datetime COMMENT '优惠卷码使用时间'")
    private Date useTime;
    //入托剩余天数
    private Integer tuoRemainingNum;
    //早教剩余天数
    private Integer zaoRemainingNum;
    private Integer lastZaoNum;
    private Integer lastTuoNum;

    @Transient
    private Integer month;

    @Column( columnDefinition = "VARCHAR(255)  NULL COMMENT '宝宝大名'")
    private String childBigName;


    @Column(columnDefinition = "VARCHAR(255) COMMENT '宝宝乳名'")
    private String childNickName;

    @Column( columnDefinition = "INT COMMENT '宝宝年龄'")
    private Integer childAge;

    public Children(String childrenName, String nickName, Integer gender, Date birthday, String weight, String height, String header, String address){
        this.setName(childrenName);
        this.setNickName(nickName);
        this.setGender(gender);
        this.setAddress(address);
        this.setStatus(ChildrenConstant.ChildrenStatus.ACTIVE.codeOf());
        this.setBirthday(birthday);
        this.setHeight(height);
        this.setWeight(weight);
        this.setHeader(header);
    }

    public static Children of(String name, String nickName, Integer gender, Date birthday, String areaId, String address, String crmClienteleId, String staffId){
        Children children = new Children();
        children.setName(name);
        children.setNickName(nickName);
        children.setBirthday(birthday);
        children.setStatus(ChildrenConstant.ChildrenStatus.NON_ACTIVE.codeOf());
        children.setAreaId(areaId);
        children.setAddress(address);
        children.setStaffId(staffId);
        children.setCrmClienteleId(crmClienteleId);
        children.setGender(gender);
        return children;
    }

    public static Children of_now(String name, String nickName, Integer gender, Date birthday, String areaId, String address, String staffId){
        Children children = new Children();
        //先强制赋值
        children.setChildBigName("12");
        children.setName(name);
        children.setChildNickName(nickName);
        children.setBirthday(birthday);
        children.setStatus(ChildrenConstant.ChildrenStatus.NON_ACTIVE.codeOf());
        children.setAreaId(areaId);
        children.setAddress(address);
        children.setStaffId(staffId);
        children.setGender(gender);
        return children;
    }

    public static Children of_crm(String name, String nickName, Integer gender, Date birthday, String areaId, String address, String crmClienteleId, String staffId,Integer childAge,String idCard,String imgUrl){
        Children children = new Children();
        children.setName(name);
        children.setNickName(nickName);
        children.setBirthday(birthday);
        children.setStatus(ChildrenConstant.ChildrenStatus.NON_ACTIVE.codeOf());
        children.setAreaId(areaId);
        children.setAddress(address);
        children.setChildAge(childAge);
        children.setStaffId(staffId);
        children.setCrmClienteleId(crmClienteleId);
        children.setGender(gender);
        children.setIdCard(idCard);
        children.setImgUrl(imgUrl);
        return children;
    }

    public static Children of_new(String name, String nickName, Integer gender, Date birthday, String areaId, String address, String crmClienteleId, String staffId,String weight,String height,String header,String remark,String allergy,String diseasesHistory,String place){
        Children children = new Children();
        children.setName(name);
        children.setNickName(nickName);
        children.setBirthday(birthday);
        children.setStatus(ChildrenConstant.ChildrenStatus.NON_ACTIVE.codeOf());
        children.setAreaId(areaId);
        children.setAddress(address);
        children.setStaffId(staffId);
        children.setCrmClienteleId(crmClienteleId);
        children.setGender(gender);
        children.setWeight(weight);
        children.setHeader(header);
        children.setHeight(height);
        children.setRemark(remark);
        children.setAllergy(allergy);
        children.setDiseasesHistory(diseasesHistory);
        children.setPlace(place);
        return children;
    }


    public Children merge(Children children) {
        try {
            ModelUtil.copyNotNullPropertiesExcludeId(this, children);
        } catch (Exception e) {
            throw new BusinessException(ErrorCode.ENTITY_MERGE_ERROR, "拷贝属性出错");
        }
        return this;
    }

}
